/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 周斌
 * Date: 2024-06-11
 * Time: 16:37
 */
public class Deom17 {
    public static void main(String[] args) {
        Object locker1 = new Object();
        Object locker2 = new Object();
        Thread t1 = new Thread(() -> {
            synchronized (locker1) {
                System.out.println("t1线程获得了locker1");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("t1线程释放了locker1");
                synchronized (locker2) {
                    System.out.println("t1线程获取到了locker2");
                }
            }
        });
        Thread t2 = new Thread(() -> {
            synchronized (locker1) {
                System.out.println("t2线程获得了locker1");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("t2线程释放了locker1");
                synchronized (locker2) {
                    System.out.println("t2线程获取到了locker2");
                }
            }
        });
        t1.start();
        t2.start();
    }
}
